from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-19 14:34:11.874427
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 19, Jan, 2021
Time: 14:34:15
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.3027
Nobs: 176.000 HQIC: -46.2664
Log likelihood: 1971.71 FPE: 4.18457e-21
AIC: -46.9240 Det(Omega_mle): 2.54477e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.443437 0.146034 3.037 0.002
L1.Burgenland 0.132249 0.076417 1.731 0.084
L1.Kärnten -0.233992 0.062070 -3.770 0.000
L1.Niederösterreich 0.131191 0.176630 0.743 0.458
L1.Oberösterreich 0.220591 0.151321 1.458 0.145
L1.Salzburg 0.182291 0.080333 2.269 0.023
L1.Steiermark 0.093532 0.109128 0.857 0.391
L1.Tirol 0.155990 0.072736 2.145 0.032
L1.Vorarlberg 0.013931 0.069403 0.201 0.841
L1.Wien -0.124849 0.146829 -0.850 0.395
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.510709 0.186321 2.741 0.006
L1.Burgenland 0.013460 0.097499 0.138 0.890
L1.Kärnten 0.372623 0.079194 4.705 0.000
L1.Niederösterreich 0.119547 0.225359 0.530 0.596
L1.Oberösterreich -0.177316 0.193067 -0.918 0.358
L1.Salzburg 0.179099 0.102495 1.747 0.081
L1.Steiermark 0.249159 0.139235 1.789 0.074
L1.Tirol 0.142559 0.092802 1.536 0.124
L1.Vorarlberg 0.191364 0.088549 2.161 0.031
L1.Wien -0.587580 0.187336 -3.137 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307381 0.064935 4.734 0.000
L1.Burgenland 0.112042 0.033979 3.297 0.001
L1.Kärnten -0.024750 0.027600 -0.897 0.370
L1.Niederösterreich 0.054772 0.078539 0.697 0.486
L1.Oberösterreich 0.277711 0.067286 4.127 0.000
L1.Salzburg 0.001811 0.035720 0.051 0.960
L1.Steiermark -0.021396 0.048524 -0.441 0.659
L1.Tirol 0.095985 0.032342 2.968 0.003
L1.Vorarlberg 0.128594 0.030860 4.167 0.000
L1.Wien 0.074262 0.065288 1.137 0.255
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209900 0.076144 2.757 0.006
L1.Burgenland -0.006352 0.039845 -0.159 0.873
L1.Kärnten 0.024792 0.032364 0.766 0.444
L1.Niederösterreich 0.028228 0.092097 0.307 0.759
L1.Oberösterreich 0.382283 0.078901 4.845 0.000
L1.Salzburg 0.094528 0.041886 2.257 0.024
L1.Steiermark 0.187593 0.056901 3.297 0.001
L1.Tirol 0.044157 0.037925 1.164 0.244
L1.Vorarlberg 0.100419 0.036187 2.775 0.006
L1.Wien -0.067815 0.076558 -0.886 0.376
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.550409 0.151723 3.628 0.000
L1.Burgenland 0.073202 0.079394 0.922 0.357
L1.Kärnten 0.006307 0.064488 0.098 0.922
L1.Niederösterreich -0.027117 0.183511 -0.148 0.883
L1.Oberösterreich 0.130102 0.157216 0.828 0.408
L1.Salzburg 0.049829 0.083462 0.597 0.550
L1.Steiermark 0.122770 0.113380 1.083 0.279
L1.Tirol 0.222848 0.075570 2.949 0.003
L1.Vorarlberg 0.018347 0.072106 0.254 0.799
L1.Wien -0.132838 0.152549 -0.871 0.384
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157237 0.107554 1.462 0.144
L1.Burgenland -0.022444 0.056281 -0.399 0.690
L1.Kärnten -0.011864 0.045715 -0.260 0.795
L1.Niederösterreich 0.160711 0.130088 1.235 0.217
L1.Oberösterreich 0.378333 0.111448 3.395 0.001
L1.Salzburg -0.030246 0.059165 -0.511 0.609
L1.Steiermark -0.038240 0.080373 -0.476 0.634
L1.Tirol 0.191499 0.053570 3.575 0.000
L1.Vorarlberg 0.050686 0.051115 0.992 0.321
L1.Wien 0.171314 0.108139 1.584 0.113
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.234460 0.135505 1.730 0.084
L1.Burgenland 0.073088 0.070907 1.031 0.303
L1.Kärnten -0.050706 0.057595 -0.880 0.379
L1.Niederösterreich -0.053070 0.163896 -0.324 0.746
L1.Oberösterreich -0.101539 0.140411 -0.723 0.470
L1.Salzburg 0.029546 0.074541 0.396 0.692
L1.Steiermark 0.376759 0.101260 3.721 0.000
L1.Tirol 0.508240 0.067492 7.530 0.000
L1.Vorarlberg 0.196741 0.064399 3.055 0.002
L1.Wien -0.211058 0.136243 -1.549 0.121
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112476 0.158656 0.709 0.478
L1.Burgenland 0.018555 0.083022 0.223 0.823
L1.Kärnten -0.105629 0.067435 -1.566 0.117
L1.Niederösterreich 0.238729 0.191897 1.244 0.213
L1.Oberösterreich 0.025673 0.164400 0.156 0.876
L1.Salzburg 0.219600 0.087276 2.516 0.012
L1.Steiermark 0.129006 0.118561 1.088 0.277
L1.Tirol 0.097756 0.079023 1.237 0.216
L1.Vorarlberg 0.021708 0.075401 0.288 0.773
L1.Wien 0.250866 0.159520 1.573 0.116
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.582827 0.086401 6.746 0.000
L1.Burgenland -0.023513 0.045212 -0.520 0.603
L1.Kärnten -0.000448 0.036724 -0.012 0.990
L1.Niederösterreich -0.024402 0.104504 -0.234 0.815
L1.Oberösterreich 0.275674 0.089530 3.079 0.002
L1.Salzburg 0.010556 0.047529 0.222 0.824
L1.Steiermark 0.011083 0.064566 0.172 0.864
L1.Tirol 0.076259 0.043034 1.772 0.076
L1.Vorarlberg 0.168115 0.041062 4.094 0.000
L1.Wien -0.071552 0.086872 -0.824 0.410
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.150125 -0.009647 0.215082 0.257577 0.066377 0.084637 -0.073104 0.158902
Kärnten 0.150125 1.000000 0.005199 0.193330 0.158801 -0.122093 0.163260 0.027070 0.306816
Niederösterreich -0.009647 0.005199 1.000000 0.288722 0.080350 0.218182 0.110223 0.062384 0.345554
Oberösterreich 0.215082 0.193330 0.288722 1.000000 0.293297 0.312821 0.086765 0.077875 0.124087
Salzburg 0.257577 0.158801 0.080350 0.293297 1.000000 0.161120 0.070522 0.073157 -0.016709
Steiermark 0.066377 -0.122093 0.218182 0.312821 0.161120 1.000000 0.105656 0.085973 -0.109999
Tirol 0.084637 0.163260 0.110223 0.086765 0.070522 0.105656 1.000000 0.146410 0.131954
Vorarlberg -0.073104 0.027070 0.062384 0.077875 0.073157 0.085973 0.146410 1.000000 0.089691
Wien 0.158902 0.306816 0.345554 0.124087 -0.016709 -0.109999 0.131954 0.089691 1.000000